package com.dao.impl;

import com.bean.Collect;
import com.dao.CollectDao;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class CollectDaoImpl extends BaseDao implements CollectDao {
    @Override
    public int add(String collectid, String userid, Integer flowerid, Date createtime) {
        String sql="insert into collect(`collectid`,`userid`,`flowerid`,`createtime`)values(?,?,?,?)";
        return update(sql,collectid,userid,flowerid,createtime);
    }

    @Override
    public List<Collect> queryByUserid(String userid) {
        String sql="select `collectid`,`userid`,`flowerid`,`createtime` from collect where userid=? ORDER BY `createtime`desc";
        return queryForList(Collect.class,sql,userid);
    }

    @Override
    public int deleteByCollectid(String collectid) {
        String sql="delete from collect where collectid=?";
        return update(sql,collectid);
    }

    @Override
    public int deleteByUserid(String userid) {
        String sql="delete from collect where userid=?";
        return update(sql,userid);
    }

    @Override
    public List<Map<String, Object>> listquery(String userid) {
        String sql="select * from collect,flower_detail where userid=? and collect.flowerid=flower_detail.flowerid";
        return listquery(Collect.class,sql,userid);
    }

    @Override
    public Collect existsId(String userid, Integer flowerid) {
        String sql="select `collectid`,`userid`,`flowerid`,`createtime` from collect where userid=? and flowerid=?";
        return queryForOne(Collect.class,sql,userid,flowerid);
    }
}
